//
//  RightDetailTableviewCell.m
//  MemoryTravel
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 fcx. All rights reserved.
//

#import "RightDetailTableviewCell.h"

@implementation RightDetailTableviewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        [self createSubviews];
    }

    return self;
}

- (void)createSubviews{

    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20 * WID, 20 * HEI)];
    [self.contentView addSubview:self.titleLabel];

    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30 * WID, 30 * HEI)];
    [self.contentView addSubview:self.descriptionLabel];

    self.blueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.contentView addSubview:self.blueLabel];
}

-(void)setPlaceDetailModel:(RightDetailModel *)placeDetailModel{

    _placeDetailModel = placeDetailModel;

    self.titleLabel.frame = CGRectMake(30 * WID, 20 * HEI, Width - 60 * WID, 30 * HEI);
    self.titleLabel.text = self.placeDetailModel.title;
    self.titleLabel.numberOfLines = 0;
    [self.titleLabel sizeToFit];
    self.titleLabel.font = [UIFont systemFontOfSize:17];

    self.blueLabel.frame = CGRectMake(self.titleLabel.frame.origin.x - 15 * WID, self.titleLabel.frame.origin.y, 5 * WID, self.titleLabel.frame.size.height);
    self.blueLabel.backgroundColor = [UIColor blueColor];

    self.descriptionLabel.text = self.placeDetailModel.detailDescription;
    self.descriptionLabel.frame = CGRectMake(15 * WID, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height , Width - 30 * WID, 1000);
    self.descriptionLabel.numberOfLines = 0;
    [self.descriptionLabel sizeToFit];
    self.descriptionLabel.font = [UIFont systemFontOfSize:17];

    CGFloat height = [RightDetailTableviewCell heightForContent:self.placeDetailModel.detailDescription];

    CGRect tempFrame = self.descriptionLabel.frame;

    tempFrame.size.height = height;
    
    self.descriptionLabel.frame = tempFrame;
}

+(CGFloat)heightForContent:(NSString *)content{

    CGSize size = CGSizeMake(Width - 30 * WID, 10000);

    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0],NSFontAttributeName, nil];

    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

    return frame.size.height;
}


@end
